package bma.common.netty.protobuf.core.impl;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;

import bma.common.netty.protobuf.core.PClient;
import bma.common.netty.protobuf.core.PClientCloseListener;

public abstract class PClientNetty implements PClient {

	protected Channel channel;

	public PClientNetty(Channel channel) {
		super();
		this.channel = channel;
	}

	@Override
	public boolean isOpen() {
		return channel.isOpen();
	}

	@Override
	public void addCloseListener(final PClientCloseListener lis) {
		channel.getCloseFuture().addListener(new ChannelFutureListener() {

			@Override
			public void operationComplete(ChannelFuture future)
					throws Exception {
				lis.onClose();
			}
		});
	}

}
